package com.wzxy.nc.dao.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import com.wzxy.nc.dao.ISysUserDao;
import com.wzxy.nc.entity.SysUser;

@Repository
public class SysUserDao extends BaseDao<SysUser> implements ISysUserDao {

	@Override
	public List<SysUser> findByUsernameAndPassword(String username, String password) {
		StringBuffer hql = new StringBuffer("from SysUser u where 1 = 1");
		hql.append(" and u.username = '" + username + "'");
		hql.append(" and u.password = '" + password + "'");
		return list(hql.toString(), null);
	}

	@Override
	public SysUser findByUsername(String username) {
		StringBuffer hql = new StringBuffer("from SysUser u where 1 = 1");
		hql.append(" and u.username = '" + username + "'");
		hql.append(" and u.deleteFlag = 0");
		List<SysUser> userList = list(hql.toString(), null);
		return userList.size() == 0 ? null : userList.get(0);
	}

	@Override
	public List<SysUser> findByUser(SysUser user) {
		StringBuffer hql = new StringBuffer("from SysUser u where 1 = 1");
		hql.append(" and u.deleteFlag = 0");
		if(user == null){
			return list(hql.toString(), null);
		}
		if(StringUtils.isNotBlank(user.getName())){
			hql.append(" and u.name = '" + user.getName() + "'");
		}		
		return list(hql.toString(), null);
	}

}
